﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;
using DiaoPaiDaYin;
using DXApplicationTangche;
using DXApplicationTangche.UC.门店下单.form;
using DXApplicationTangche.UC.门店下单.DTO;
using DXApplicationTangche.UC.款式异常;
using DXApplicationTangche.DTO;
using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.service;
using DXApplicationTangche.UC.坚山;
using DXApplicationTangche.UC.门店下单.UC;

namespace mendian
{
    class ImpService
    {
        #region 无引用
        /// <summary>
        /// 字符串按指定长度换行
        /// </summary>
        /// <param name="conten">字符串</param>
        /// <param name="start">指定长度</param>
        /// <param name="sSymbol">换行符</param>
        /// <returns>按指定长度换行后的字符串</returns>
        public static String SqritBySymbol(string conten, int start, string sSymbol)
        {
            string str = "";
            char[] param = conten.ToCharArray();
            if (param.Length > 0)
            {
                if (param.Length > start)
                {
                    int j = 1;
                    for (int i = 0; i < param.Length; i++)
                    {
                        str += param[i];
                        if (i == (start * j))
                        {
                            j++;
                            str = str + sSymbol;
                        }
                    }
                }
            }
            return str;
        }

        /// <summary>
        /// 下载图片
        /// </summary>
        /// <param name="url"></param>
        /// <param name="path"></param>
        /// <param name="FileName"></param>
        public static void DownloadPic(String url, String path, String FileName)
        {
            //string path = "http://www.quanjing.com/imgbuy/QJ9107100567.png";//下载图片的地址
            //string newPath = string.Format(@"D:\UPLOAD\");//目标地址
            //string ImsFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".png"; //目标文件名
            try
            {
                System.Net.WebRequest imgRequest = System.Net.WebRequest.Create(url);
                HttpWebResponse res;
                try
                {
                    res = (HttpWebResponse)imgRequest.GetResponse();
                }
                catch (WebException ex)
                {
                    res = (HttpWebResponse)ex.Response;
                }
                if (res.StatusCode.ToString() == "OK")
                {
                    System.Drawing.Image dwonImage = System.Drawing.Image.FromStream(imgRequest.GetResponse().GetResponseStream());
                    if (!System.IO.Directory.Exists(path))//目标地址不存在自动创建
                    {
                        System.IO.Directory.CreateDirectory(path);
                    }
                    dwonImage.Save(path + FileName);
                    dwonImage.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw;
            }

        }
        #endregion

    }
}

